package com.ssl.pdf.util;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * 描述：
 *
 * @author ssl
 * @create 2021/7/9 0009.
 */
public class ImageUtil {

    public static byte[] bufferedImageToBytes(BufferedImage bufferedImage, String imageType) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ImageIO.write(bufferedImage, imageType, byteArrayOutputStream);
        byte[] imageBytes = byteArrayOutputStream.toByteArray();
        return imageBytes;
    }

    public static BufferedImage bytesToBufferedImage(byte[] imageBytes) throws IOException {
        ByteArrayInputStream sealImageInputStream = new ByteArrayInputStream(imageBytes);
        BufferedImage bufferedImage = ImageIO.read(sealImageInputStream);
        return bufferedImage;
    }
}
